package com.asiainfo.work.eorror;

import com.asiainfo.work.utils.BaseResultCode;
import com.asiainfo.work.utils.ErrorResultCode;
import lombok.Getter;

/**
 * 统一的业务处理类
 *
 * @author: bf
 * @date: 2021/1/7-21:24
 */
public class ServiceException extends RuntimeException {

    private static final long serialVersionUID = 2359767895161832954L;

    @Getter
    private String code;

    public ServiceException(String code, String message) {
        super(message);
        this.code = code;
    }


    public ServiceException(ErrorResultCode errorResultCode) {
        super(errorResultCode.getMsg());
        this.code = errorResultCode.getCode();
    }

    public ServiceException(ErrorResultCode resultCode, Throwable cause) {
        super(cause);
        this.code = resultCode.getCode();
    }

    public ServiceException(String message) {
        super(message);
        this.code = BaseResultCode.FAILURE.getCode();
    }

    public ServiceException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public ServiceException(BaseResultCode resultCode) {
        super(resultCode.getMsg());
        this.code = resultCode.getCode();
    }

    public ServiceException(BaseResultCode resultCode, String msg) {
        super(msg);
        this.code = resultCode.getCode();
    }

    @Deprecated
    public ServiceException(BaseResultCode resultCode, Throwable cause) {
        super(cause);
        this.code = resultCode.getCode();
    }

    public ServiceException(String msg, Throwable cause) {
        super(msg, cause);
        this.code = BaseResultCode.FAILURE.getCode();
    }

    /**
     * for better performance
     *
     * @return Throwable
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public Throwable doFillInStackTrace() {
        return super.fillInStackTrace();
    }
}
